home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC]
/
NeXTSTEP 3.3 Dev Intel.iso
/
NextDeveloper
/
Source
/
GNU
/
build_gcc
next >
Wrap
Text File
|
1994-05-04
|
16KB
|
607 lines
#!/bin/sh
############################################################
##
## implementation of the "build" target of cc makefile
##
############################################################
PATH=/bin:/usr/bin
export PATH
# what targets to produce compilers to
TARGETS=`arch`
# what host we should produce executables for
HOSTS=`arch`
# the host on which we are running at now
BUILD=`arch`
# where to do the build .. better have lots of space there!
SRCROOT=~comp/cc_proj/cc
# where to do the build .. better have lots of space there!
OBJROOT=
# where to do the build .. better have lots of space there!
SYMROOT=
# where to do the build .. better have lots of space there!
DSTROOT=
# where to do the build .. better have lots of space there!
BUILDROOT=/private/tmp
# what compilers to build. On NeXT, we only use those two.
LANGUAGES="objc objc++"
# Optimize flags when compiling the compiler
CFLAGS=-g
OPTIMIZE=-O
result=fats
for arg
do
case $next_arg in
--srcroot)
SRCROOT=$arg
next_arg=
;;
--objroot)
OBJROOT=$arg
next_arg=
;;
--dstroot)
DSTROOT=$arg
next_arg=
;;
--symroot)
SYMROOT=$arg
next_arg=
;;
--buildroot)
BUILDROOT=$arg
next_arg=
;;
--host*)
HOSTS=$arg
next_arg=
;;
--target*)
TARGETS=$arg
next_arg=
;;
--cflags)
CFLAGS=$arg
next_arg=
;;
*)
case $arg in
--srcroot=*)
SRCROOT=`echo $arg | sed 's/-*s[a-z]*=//'`
;;
--objroot=*)
OBJROOT=`echo $arg | sed 's/-*o[a-z]*=//'`
;;
--dstroot=*)
DSTROOT=`echo $arg | sed 's/-*d[a-z]*=//'`
;;
--symroot=*)
SYMROOT=`echo $arg | sed 's/-*s[a-z]*=//'`
;;
--buildroot=*)
BUILDROOT=`echo $arg | sed 's/-*b[a-z]*=//'`
;;
--hosts=*|--host=*)
HOSTS=`echo $arg | sed 's/-*h[a-z]*=//'`
;;
--targets=*|--target=*)
TARGETS=`echo $arg | sed 's/-*t[a-z]*=//'`
;;
--cflags=*)
CFLAGS=`echo $arg | sed 's/-*c[a-z]*=//'`
;;
--optimize=*)
if [ `echo $arg | sed 's/-*o[a-z]*=//'` = yes ]; then
OPTIMIZE=-O
else
OPTIMIZE=
fi
;;
--fat|--fats)
result=fats
;;
--thin|--thins)
result=thins
;;
--clean)
result=clean
;;
--configure)
result=configure
;;
--optimize)
OPTIMIZE=-O
;;
--no-optimize)
OPTIMIZE=
;;
--*)
next_arg=$arg
;;
*)
echo unknown option $arg
exit 1
;;
esac
esac
done
# get the version
CCVERS=`cd $SRCROOT; vers_string -f cc`
# remove any -arch flags from CFLAGS
CFLAGS=`echo $CFLAGS|sed 's/-arch [a-z0-9]*//g'`
# add target arch...
if [ x$RC_RELEASE != x ]; then
CFLAGS="$CFLAGS -DRC_RELEASE_"`echo $RC_RELEASE|tr '.' '_'`
fi
if [ x$SYMROOT = x ]; then
SYMROOT=$BUILDROOT/$CCVERS.sym
fi
if [ x$OBJROOT = x ]; then
OBJROOT=$BUILDROOT/$CCVERS.obj
fi
if [ x$DSTROOT = x ]; then
DSTROOT=$BUILDROOT/$CCVERS.dst
fi
# set up bison environment
BISON=$OBJROOT/bison_`arch`_obj/bison
BISON_SIMPLE=$BISON.s1
export BISON_SIMPLE
echo ===========================================================
echo == 'Building NeXT C compiler(s) **' $result '**'
echo ===========================================================
echo == 'HOSTS :' ${HOSTS}
echo == 'TARGETS :' ${TARGETS}
echo == 'BUILDHOST :' `hostname` -- a `arch`
echo == 'OBJROOT :' ${OBJROOT}
echo == 'SYMROOT :' ${SYMROOT}
echo == 'SRCROOT :' ${SRCROOT}
echo == 'DSTROOT :' ${DSTROOT}
echo == 'VERSION :' ${CCVERS}
echo == 'CFLAGS :' ${OPTIMIZE} ${CFLAGS}
echo ===========================================================
#
# Check that cross compilers are available
#
missing_cross=no
for host in ${HOSTS}; do
if [ -d /lib/$host ]; then true; else
echo "************************************************************"
echo "** You must have a cross compiler for $host installed"
missing_cross=yes
fi;
done
for host in $HOSTS; do
if echo $TARGETS | grep $host > /dev/null 2>&1; then true; else
echo '************************************************************'
echo '**' "hosttype $host must also be a target"
missing_cross=yes
fi
done
if [ $missing_cross = yes ]; then
echo "************************************************************"
exit 1;
fi
safe_exec () {
if ($*); then true; else exit 1; fi
}
clean_gcc () {
echo ===========================================================
echo == 'Cleaning NeXT C compiler(s)'
echo ===========================================================
for target in ${TARGETS}; do
for host in ${HOSTS}; do
echo '==' ${OBJROOT}/cc-$target-on-$host;
if [ -d ${OBJROOT}/cc-$target-on-$host ]; then
/bin/rm -Rf ${OBJROOT}/cc-$target-on-$host;
fi
done
done
for host in ${HOSTS}; do
if [ -d ${SYMROOT}/$host ]; then
echo '==' ${SYMROOT}/$host;
/bin/rm -Rf ${SYMROOT}/$host;
fi
done
if [ X${DSTROOT} != X${SRCROOT} ]; then
if [ -d ${DSTROOT} ]; then
echo '==' ${DSTROOT};
/bin/rm -Rf ${DSTROOT};
fi
fi
echo ===========================================================
}
configure_gcc () {
for target in ${TARGETS}; do
for host in ${HOSTS}; do
mkdirs ${OBJROOT}/cc-$target-on-$host;
cd ${OBJROOT}/cc-$target-on-$host;
source=bad
if [ -f make.id ]; then
if [ X`cat make.id` = X${SRCROOT}/cc:`arch` ]; then
source=ok
fi
fi
if [ X$source = Xok -a -f Makefile ]; then
echo ===========================================================;
echo == updating Makefile for cc-$target-on-$host\; buildhost=`arch`
echo ===========================================================;
safe_exec make Makefile
else
echo ===========================================================;
echo == configuring cc-$target-on-$host\; buildhost=`arch`
echo ===========================================================;
/bin/rm -f make.id
echo ${SRCROOT}/cc:`arch` > make.id
/bin/rm -f rtl.o bc-*.o
${SRCROOT}/cc/configure \
--host=$host-next-mach \
--target=$target-next-mach \
--build=`arch`-next-mach \
--srcdir=${SRCROOT}/cc \
--force-build;
fi;
done;
done
}
install_newer () {
if [ -f "$1" ]; then
rm -f /tmp/make.$$
touch -f /tmp/make.$$
echo "$2: $1" >> /tmp/make.$$
echo " /bin/rm -f $2" >> /tmp/make.$$
echo " install -c $3 $1 $2" >> /tmp/make.$$
safe_exec make -f /tmp/make.$$
rm -f /tmp/make.$$
else
echo "build_gcc: $1: no such file"
fi
}
build_compiler () {
for host in ${HOSTS}; do
for target in ${TARGETS}; do
cd ${OBJROOT}/cc-$target-on-$host;
echo ===========================================================;
echo == building cc-$target-on-$host\; buildhost:`arch`;
echo ===========================================================;
#############################################################
# this will build the core compilers
#############################################################
if [ -d `arch` ]; then true; else mkdir `arch`; fi
if make all.build \
srcdir=${SRCROOT}/cc \
LANGUAGES="${LANGUAGES}" \
HOST_PREFIX="`arch`-" HOST_PREFIX_1="`arch`-" \
HOST_CC="cc -arch `arch` -traditional-cpp" \
BISON=${BISON} \
CFLAGS="${OPTIMIZE} ${CFLAGS}" \
CC="cc -arch $host -traditional-cpp"; \
then echo '== ok' ; else exit 1; fi
sym=$SYMROOT/$host
mkdirs $sym/lib/$target
mkdirs $sym/bin
install_newer cpp $sym/lib/$target/cpp "-m 555"
install_newer cc1obj $sym/lib/$target/cc1obj "-m 555"
install_newer cc1objplus $sym/lib/$target/cc1objplus "-m 555"
done
if echo $TARGETS | grep $host; then
install_newer ${OBJROOT}/cc-$host-on-$host/xgcc $sym/bin/cc "-m 555"
else
echo '************************************************************'
echo '**' "hosttype $host must also be a target"
echo '************************************************************'
exit 1;
fi
done
}
build_libgcc () {
for target in ${TARGETS}; do
host=`arch`
mkdirs ${OBJROOT}/cc-$target-on-$host;
cd ${OBJROOT}/cc-$target-on-$host;
# the buildhost is in hosts..
if echo $HOSTS | grep $host; then
#############################################################
# now, build the gcc specs and runtime libraries
#############################################################
echo "============================================================"
echo "== Building runtime libraries, using new compiler:"
./xgcc -B./ -v
echo "============================================================"
echo '== building static version'
if [ -f libgcc_static.a ]; then mv -f libgcc_static.a libgcc.a; fi
if [ -f libgcc1_static.a ]; then mv -f libgcc1_static.a libgcc1.a; fi
if [ -f libgcc2_static.a ]; then mv -f libgcc2_static.a libgcc2.a; fi
if make specs libgcc1.a libgcc.a \
srcdir=${SRCROOT}/cc \
LANGUAGES="${LANGUAGES}" \
HOST_PREFIX="`arch`-" HOST_PREFIX_1="`arch`-" \
HOST_CC="cc -arch `arch` -traditional-cpp" \
OLDCC="./xgcc -B./" \
CCLIBFLAGS="${OPTIMIZE} ${CFLAGS}" \
GCC_FOR_TARGET="./xgcc -B./" \
CFLAGS="${OPTIMIZE} ${CFLAGS}" \
BISON=${BISON} \
GCC_CFLAGS="-traditional-cpp ${CFLAGS}" \
AR_FOR_TARGET=ar LIBGCC1=libgcc1.a \
CC="cc -arch $host -traditional-cpp"; \
then echo '== ok'; else exit 1; fi
mv -f libgcc.a libgcc_static.a
mv -f libgcc1.a libgcc1_static.a
mv -f libgcc2.a libgcc2_static.a
echo '== building shlib version'
if [ -f libgcc_shlib.a ]; then mv -f libgcc_shlib.a libgcc.a; fi
if [ -f libgcc1_shlib.a ]; then mv -f libgcc1_shlib.a libgcc1.a; fi
if [ -f libgcc2_shlib.a ]; then mv -f libgcc2_shlib.a libgcc2.a; fi
if make specs libgcc1.a libgcc.a \
srcdir=${SRCROOT}/cc \
LANGUAGES="${LANGUAGES}" \
HOST_PREFIX="`arch`-" HOST_PREFIX_1="`arch`-" \
HOST_CC="cc -arch `arch` -traditional-cpp -DSHLIB" \
OLDCC="./xgcc -B./ -DSHLIB" \
CCLIBFLAGS="${OPTIMIZE} ${CFLAGS} -DSHLIB" \
GCC_FOR_TARGET="./xgcc -B./ -DSHLIB" \
CFLAGS="${OPTIMIZE} ${CFLAGS} -DSHLIB" \
BISON=${BISON} \
GCC_CFLAGS="-traditional-cpp ${CFLAGS} -DSHLIB" \
AR_FOR_TARGET=ar LIBGCC1=libgcc1.a \
CC="cc -arch $host -traditional-cpp -DSHLIB"; \
then echo '== ok'; else exit 1; fi
mv -f libgcc.a libgcc_shlib.a
mv -f libgcc1.a libgcc1_shlib.a
mv -f libgcc2.a libgcc2_shlib.a
for host in ${HOSTS}; do
sym=$SYMROOT/$host
mkdirs $sym/lib/$target
install_newer specs $sym/lib/$target/specs "-m 444"
install_newer libgcc_static.a $sym/lib/$target/libcc.a "-r -m 444"
done
libgcc=`pwd`/libgcc_shlib.a
shlib=${OBJROOT}/shlib_${target}_obj
(mkdirs $shlib; cd $shlib; ar x $libgcc)
else
############################################################
# copy specs /lib/$target...
############################################################
if [ -d /lib/$target ]; then
# get version of installed $target compiler
cc -arch $target -v 2> /tmp/tmp.$$
target_vers=`cat /tmp/tmp.$$ \
| grep 'version' \
| sed 's/, gcc.*$//' \
| sed 's/^.*version //'`
rm /tmp/tmp.$$
if [ X$target_vers != X$CCVERS ]; then
echo "************************************************************";
echo "** You must have the most resent version of the compiler "
echo "** (host=" `arch` " target=$target version=$CCVERS) installed"
echo "** on the build host to finish this build... "
echo "** Currently, version $target_vers is installed "
echo "************************************************************";
exit 1;
fi
echo "============================================================"
echo "== Building runtime libraries, using installed compiler:"
cc -arch $target -v
echo "============================================================"
rm -f specs
cp /lib/$target/specs specs
echo '== building static version'
if [ -f libgcc_static.a ]; then mv -f libgcc_static.a libgcc.a; fi
if [ -f libgcc1_static.a ]; then mv -f libgcc1_static.a libgcc1.a; fi
if [ -f libgcc2_static.a ]; then mv -f libgcc2_static.a libgcc2.a; fi
if make libgcc1.a libgcc.a \
srcdir=${SRCROOT}/cc \
LANGUAGES="${LANGUAGES}" \
HOST_PREFIX="`arch`-" HOST_PREFIX_1="`arch`-" \
HOST_CC="cc -arch `arch` -traditional-cpp" \
OLDCC="cc -arch $target" \
BISON=${BISON} \
GCC_FOR_TARGET="cc -arch $target" \
CFLAGS="${OPTIMIZE} ${CFLAGS}" \
GCC_CFLAGS="-traditional-cpp" \
AR_FOR_TARGET=ar LIBGCC1=libgcc1.a \
CC="cc -arch $host -traditional-cpp"; \
then echo '== ok'; else exit 1; fi
mv -f libgcc.a libgcc_static.a
mv -f libgcc1.a libgcc1_static.a
mv -f libgcc2.a libgcc2_static.a
echo '== building shlib version'
if [ -f libgcc_shlib.a ]; then mv -f libgcc_shlib.a libgcc.a; fi
if [ -f libgcc1_shlib.a ]; then mv -f libgcc1_shlib.a libgcc1.a; fi
if [ -f libgcc2_shlib.a ]; then mv -f libgcc2_shlib.a libgcc2.a; fi
if make libgcc1.a libgcc.a \
srcdir=${SRCROOT}/cc \
LANGUAGES="${LANGUAGES}" \
HOST_PREFIX="`arch`-" HOST_PREFIX_1="`arch`-" \
HOST_CC="cc -arch `arch` -traditional-cpp -DSHLIB" \
OLDCC="cc -arch $target -DSHLIB" \
BISON=${BISON} \
GCC_FOR_TARGET="cc -arch $target -DSHLIB" \
CFLAGS="${OPTIMIZE} ${CFLAGS} -DSHLIB" \
GCC_CFLAGS="-traditional-cpp -DSHLIB" \
AR_FOR_TARGET=ar LIBGCC1=libgcc1.a \
CC="cc -arch $host -traditional-cpp -DSHLIB"; \
then echo '== ok'; else exit 1; fi
mv -f libgcc.a libgcc_shlib.a
mv -f libgcc1.a libgcc1_shlib.a
mv -f libgcc2.a libgcc2_shlib.a
for host in ${HOSTS}; do
sym=$SYMROOT/$host
mkdirs $sym/lib/$target
install_newer /lib/$target/specs $sym/lib/$target/specs "-m 444"
install_newer /lib/$target/libgcc_static.a $sym/lib/$target/libcc.a "-r -m 444"
done
libgcc=`pwd`/libgcc_shlib.a
shlib=${OBJROOT}/shlib_${target}_obj
(mkdirs $shlib; cd $shlib; ar x $libgcc)
else
echo "************************************************************";
echo "** You must have the most resent version of the compiler "
echo "** (host=" `arch` "; target=$target; version=$CCVERS) installed"
echo "** on the build host to finish this build... "
echo "** Currently, no such compiler is installed "
echo "************************************************************";
exit 1;
fi;
fi
done
}
install_fat () {
echo "============================================================"
echo "== Building fat binaries [$HOSTS] fat for targets: $TARGETS"
echo "============================================================"
fat=$DSTROOT
sym=$SYMROOT
mkdirs $fat
mkdirs $fat/bin
mkdirs $fat/lib
for target in ${TARGETS}; do
mkdirs $fat/lib/$target;
for file in bin/cc \
lib/$target/cpp \
lib/$target/cc1obj \
lib/$target/cc1objplus; do
thin_files=""
for host in ${HOSTS}; do
thin_files="$thin_files $sym/$host/$file"
done
rm -f $fat/$file
rm -f /tmp/make.$$
touch -f /tmp/make.$$
echo "$fat/$file: $thin_files" >> /tmp/make.$$
echo " /bin/rm -f $fat/$file" >> /tmp/make.$$
echo " lipo -create -output $fat/$file $thin_files" >> /tmp/make.$$
echo " strip $fat/$file" >> /tmp/make.$$
echo " chmod 555 $fat/$file" >> /tmp/make.$$
safe_exec make -f /tmp/make.$$
rm -f /tmp/make.$$
done
install_newer $sym/$host/lib/$target/specs $fat/lib/$target/specs "-m 444"
install_newer $sym/$host/lib/$target/libcc.a $fat/lib/$target/libcc.a "-r -m 444"
done;
}
if [ X$result = Xclean ]; then
clean_gcc
exit 0
fi
configure_gcc
if [ X$result = Xconfigure ]; then
exit 0
fi
build_compiler
build_libgcc
if [ $result = thins ]; then
exit 0;
fi
install_fat